<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:app="http://springfuse.jaxio.com/app"
	xmlns:p="http://primefaces.org/ui"
	xmlns:c="http://java.sun.com/jsp/jstl/core"
	template="/WEB-INF/layouts/main.xhtml">
	<ui:define name="toolbarChildren">
		<p:toolbarGroup align="left" rendered="#{not sub and not readonly}">
			<p:commandButton id="quit" action="#{searchForm.quit()}" ajax="false" immediate="true" process="@form"
				icon="ui-icon-closethick"
				value="#{msg.menu_quit}"
				title="#{msg.menu_quit} #{resourcesUtil.getProperty(title)}" />
			<p:separator />
			<p:commandButton id="create" action="#{model.create()}" ajax="false" immediate="true" process="@this"
				icon="ui-icon-document"
				rendered="#{empty bean and permission.canCreate()}"
				value="#{msg.menu_new}"
				title="#{msg.menu_new} #{resourcesUtil.getProperty(title)}" />
		</p:toolbarGroup>
	</ui:define>
	<ui:define name="content">
		<p:fieldset id="filtersFieldset" legend="#{msg.search_criteria}" toggleable="true">
			<f:validateBean disabled="true">
				<h:panelGrid columns="4">
					<ui:insert name="filters" />
				</h:panelGrid>
			</f:validateBean>
		</p:fieldset>
		<p:commandButton id="search" actionListener="#{model.onSearch()}" process="@form"
			icon="iconSearch" styleClass="aria-search-button default"
			update="messages searchResults" value="#{msg.menu_search}"
			title="#{msg.menu_search} #{resourcesUtil.getProperty(title)}" />
		<p:commandButton id="resetSearch" icon="ui-icon-power" value="#{msg.search_reset}"
			actionListener="#{searchForm.reset()}"
			update="messages filtersFieldset searchResults searchFormName"/>
		<p:commandButton id="excel" action="#{model.onExcel()}" process="@form"
			icon="iconExcel" value="Excel" ajax="false" />
		<!--  [SAVED SEARCH] -->
		<p:autoComplete id="searchFormName" rendered="#{savedSearch}"
			value="#{searchForm.currentSavedSearch}"
			completeMethod="#{savedSearchService.finderFor(searchForm).find}"
			var="item" itemValue="#{item}" itemLabel="#{savedSearchPrinter.print(item)}" converter="#{savedSearchJsfConverter}"
			dropdown="true" size="30">
			<p:ajax event="itemSelect" update="filtersFieldset messages searchResults searchFormName" />
		</p:autoComplete>
		<p:commandButton id="displaySavedSearchPanel" rendered="#{savedSearch}" icon="ui-icon-disk" /> 		 
		<p:overlayPanel id="savedSearchPanel" widgetVar="savedSearchPanel" for="displaySavedSearchPanel" hideEffect="fade" dynamic="false"> 		 
			<h:panelGrid columns="2" styleClass="aria-role-presentation"> 		 
		    	<app:input id="savedSearchName" value="#{searchForm.searchFormName}" label="savedSearch_name" required="true" /> 		 
		      	<app:inputBoolean id="savedSearchPrivate" label="savedSearchName_private" value="#{searchForm.privateSearch}" />  		 
			</h:panelGrid> 		 
			<h:panelGroup> 		 
		    	<p:commandButton id="saveSearch" actionListener="#{savedSearchService.save(searchForm)}" process="@form" 		 
					icon="ui-icon-disk" update="filtersFieldset messages searchResults savedSearchPanel" 		 
					value="#{msg.search_save}"	 /> 		 
			</h:panelGroup> 		 
		</p:overlayPanel>
		<!-- [/SAVED SEARCH] -->
		<ui:insert name="buttons" />
		<br />
		<span style="height: 16px; display: block;">
			<p:ajaxStatus>
				<f:facet name="start">
					<h:graphicImage id="ajaxSearchLoading" name="icons/ajaxloading.gif" alt="Loading..." />
				</f:facet>
				<f:facet name="error">
					<h:outputText id="ajaxSearchError" value="#{msg.error_ajax}" />
				</f:facet>
				<f:facet name="success">
					<h:outputText id="ajaxSearchSuccess" value="" />
				</f:facet>
			</p:ajaxStatus>
		</span>
		<!-- safari/voiceover requires 'span' (not 'div') for live region-->
		<span id="searchResultsRegion" aria-label="#{msg.search_results}" aria-live="assertive" aria-relevant="additions">
		</span>
		<c:if test="#{not multiCheckboxSelection}">
			<p:dataTable id="searchResults"
				value="#{model}" var="item" lazy="true"
				paginator="true" paginatorAlwaysVisible="false" paginatorPosition="bottom"
				rowsPerPageTemplate="10,25,50,100" rows="10"
				selectionMode="single" selection="#{model.selectedRow}"
				emptyMessage="#{msg.search_empty}">
				<ui:insert name="result" />
			</p:dataTable>
		</c:if>
		<c:if test="#{multiCheckboxSelection}">
			<p:dataTable id="searchResults"
				value="#{model}" var="item" lazy="true"
				paginator="true" paginatorAlwaysVisible="false" paginatorPosition="bottom"
				rowsPerPageTemplate="10,25,50,100" rows="10"
				selection="#{model.selectedRows}"
				emptyMessage="#{msg.search_empty}">
				<p:column id="selectAll" selectionMode="multiple" style="width:18px" rendered="#{permission.canSelect()}" />
				<ui:insert name="result" />
				<f:facet name="footer">
					<app:iconMultiSelect model="#{model}" rendered="true" process="@this" />
				</f:facet>
			</p:dataTable>
		</c:if>
		<script type="text/javascript">APP.updateSearchResultsRegion('#{resourcesUtil.getPluralableProperty("search_results_status", model.rowCount)}');</script>
	</ui:define>
	<ui:define name="dialogs">
		<p:confirmDialog widgetVar="askForDeleteItemDialog" header="#{msg.menu_delete}?" message="#{msg.dialog_delete_confirm}">
			<h:panelGrid id="askForDeleteItemDialogContent" columns="2" cellpadding="4" style="margin:0 auto;">  
				<h:outputText value="#{printer.print(model.selectedRow)}" style="font-weight:bold" rendered="#{not empty model.selectedRow}"/>  
			</h:panelGrid>
			<p:commandButton id="askForDeleteItemDialogYes" action="#{model.delete()}" ajax="true" immediate="true" oncomplete="askForDeleteItemDialog.hide();" process="@this" value="#{msg.yes}" title="#{msg.dialog_delete_confirm} #{msg.yes}" icon="ui-icon-check" update=":form:searchResults :form:messages"/>
			<p:commandButton id="askForDeleteItemDialogNo" value="#{msg.no}" title="#{msg.dialog_delete_confirm} #{msg.no}" onclick="askForDeleteItemDialog.hide(); return false;" icon="ui-icon-cancel"/>
		</p:confirmDialog>
	</ui:define>
</ui:composition >